// independencies
var gulp          = require('gulp'),
    gulputil      = require('gulp-util'),
    watch         = require('gulp-watch'),
    cssmin         = require('gulp-cssmin'),
    uglify         = require('gulp-uglify'),
    rename         = require('gulp-rename'),
    concat         = require('gulp-concat');

//global config
var config = {
    default: ['watch', 'concat']
};

gulp.task('css', function(){
    return gulp.src('src/css/*.css').pipe(gulp.dest('./dist/css/'));
});

gulp.task('flash', function(){
    return gulp.src('vendor/webuploader/Uploader.swf').pipe(gulp.dest('./dist/js/'));
});

gulp.task('concat', function(){
    return gulp.src(['vendor/webuploader/webuploader.js', 'src/js/intro.js', 'src/js/template.js', 'src/js/api.js', 'src/js/image.js', 'src/js/modal.js', 'src/js/directive.js', 'src/js/outro.js'])
               .pipe(concat('angular-qiniu-uploader.js'))
               .pipe(gulp.dest('./dist/js/'));
});

gulp.task('watch', function(){
    gulp.watch('src/js/*.js', ['concat']);
    gulp.watch('src/css/*.css', ['css']);
});

gulp.task('build', function(){
    gulp.src('dist/css/*.css').pipe(cssmin()).pipe(rename({suffix: '.min'})).pipe(gulp.dest('build'));
    gulp.src('dist/js/*.js').pipe(uglify()).pipe(rename({suffix: '.min'})).pipe(gulp.dest('build'));
});

gulp.task('default', ['watch', 'css']);